package com.airticketbooking.controller.manager;

import com.airticketbooking.common.domain.PageDTO;
import com.airticketbooking.common.domain.R;
import com.airticketbooking.query.FlightSchedulePageQuery;
import com.airticketbooking.vo.FlightScheduleVO;
import com.airticketbooking.service.FlightShceduleService;
import com.github.pagehelper.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author Mr.J
 * @version 1.0.0
 * @date 2024/10/8
 * @desc
 */
@RequestMapping("/air/manager/flightSchedule")
@RestController
@Api(tags = "班次管理")
@RequiredArgsConstructor
@Slf4j
public class FlightScheduleController {


	private final FlightShceduleService flightShceduleService;

	/***
	 * @param flightSchedulePageQuery
	 * @return: com.airticketbooking.common.domain.R<com.airticketbooking.common.domain.PageDTO < com.airticketbooking.domain.vo.FlightShceduleVO>>
	 * @Author: susu
	 * @date: 2024/10/21
	 * @since 1.0.0
	 * @Description:
	 */
	@ApiOperation("分页获取所有班次信息")
	@GetMapping("/page")
	public R<PageDTO<FlightScheduleVO>> list(FlightSchedulePageQuery flightSchedulePageQuery) throws Exception {

		Page<FlightScheduleVO> flightPageinfo = flightShceduleService.list(flightSchedulePageQuery);

		PageDTO<FlightScheduleVO> pageDTO = new PageDTO<>();
		pageDTO.setTotal(flightPageinfo.getTotal());
		pageDTO.setList(flightPageinfo.getResult());

		return R.ok(pageDTO);

	}

	//	根据id查询班次信息
	@ApiOperation("根据id查询班次信息")
	@GetMapping("/{id}")
	public R<FlightScheduleVO> getById(@PathVariable("id") int id) throws Exception {

		log.info("查询班次信息id:{}", id);
		FlightScheduleVO flightScheduleVO = flightShceduleService.getShceduleVOById(id);

		log.info("get flight by id Result:{}", flightScheduleVO);
		return R.ok(flightScheduleVO);
	}

	//	更改班次信息
	@ApiOperation("更改班次信息")
	@GetMapping()
	public R<String> modifyStatus(Integer id, Integer status) throws Exception {


		try {
			flightShceduleService.modifyStatus(id, status);
			return R.ok("修改成功");
		} catch (Exception e) {
			return R.error(e.getMessage());
		}

	}


}
